package org.mch.func.file.coding;

import java.awt.Color;
import java.awt.Font;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import org.mch.biz.ui.BizEvent;
import org.mch.biz.ui.BizPanel;
import org.mch.swingm.core.MButton;
import org.mch.swingm.ext.MEComboBox;
import org.mch.swingm.ext.METextChooser;

/**
 * 描述：文件编码转换；<BR>
 *
 * @author MCH；<BR>
 *
 */
public class ClientPanel extends BizPanel {
	private static final long serialVersionUID = 1L;
	private METextChooser textChooser_Old;
	private METextChooser textChooser_New;
	private JScrollPane scrollPane;
	private JTextArea text_filetype;
	private JScrollPane scrollPane_1;
	private JTextArea text_gbkToUTF8;
	private JScrollPane scrollPane_2;
	private JTextArea text_utf8ToGBK;
	private MEComboBox<String> comboConverType;
	private MButton btn_execute;
	private JCheckBox check_iscopynotconverfile;

	public ClientPanel() {
		super();
		initGUI();
	}

	private void initGUI() {
		setBorder(new LineBorder(Color.LIGHT_GRAY));
		setLayout(null);
		add(getTextChooser_Old());
		add(getTextChooser_New());
		add(getScrollPane());
		add(getScrollPane_1());
		add(getScrollPane_2());
		add(getComboConverType());
		add(getBtn_execute());
		add(getCheck_iscopynotconverfile());
	}

	protected BizEvent createEvent() {
		return new ClientEvent(this);
	}

	public METextChooser getTextChooser_Old() {
		if (textChooser_Old == null) {
			textChooser_Old = new METextChooser("原编码文件夹：");
			textChooser_Old.getLabel().setForeground(Color.BLACK);
			textChooser_Old.getLabel().setFont(new Font("宋体", Font.PLAIN, 14));

			// 设置能选择文件和文件夹
			// textChooser_Old.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

			// 设置只能选择文件夹
			textChooser_Old.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			textChooser_Old.setBounds(12, 12, 864, 32);
		}
		return textChooser_Old;
	}

	public METextChooser getTextChooser_New() {
		if (textChooser_New == null) {
			textChooser_New = new METextChooser("新编码文件夹：");
			textChooser_New.getLabel().setForeground(Color.RED);
			textChooser_New.getLabel().setFont(new Font("宋体", Font.PLAIN, 14));
			textChooser_New.setBounds(12, 56, 864, 32);

			// 设置只能选择文件夹
			textChooser_New.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		}
		return textChooser_New;
	}

	public JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setFont(new Font("Dialog", Font.PLAIN, 12));
			scrollPane.setBorder(new TitledBorder(null, "需转换的文件类型：", TitledBorder.LEADING, TitledBorder.TOP, new Font("宋体",
					Font.PLAIN, 13), null));
			scrollPane.setBounds(12, 134, 167, 294);
			scrollPane.setViewportView(getText_filetype());
		}
		return scrollPane;
	}

	public JTextArea getText_filetype() {
		if (text_filetype == null) {
			text_filetype = new JTextArea();
			text_filetype.setBorder(new LineBorder(Color.LIGHT_GRAY));
			text_filetype.setFont(new Font("宋体", Font.PLAIN, 13));
			text_filetype.setText("java\nphp\njsp\nhtml\nhtm\nftl\nvm\ntxt\njs\ncss\nini\ninc\nasp");
		}
		return text_filetype;
	}

	public JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setFont(new Font("Dialog", Font.PLAIN, 12));
			scrollPane_1.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)),
					"GBK-UTF8 \u6587\u672C\u66FF\u6362\u89C4\u5219\uFF1A", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			scrollPane_1.setBounds(191, 134, 204, 294);
			scrollPane_1.setViewportView(getText_gbkToUTF8());
		}
		return scrollPane_1;
	}

	public JTextArea getText_gbkToUTF8() {
		if (text_gbkToUTF8 == null) {
			text_gbkToUTF8 = new JTextArea();
			text_gbkToUTF8.setText("gbk=UTF-8\r\ngb2312=UTF-8\r\nGBK=UTF-8\r\nGB2312=UTF-8");
			text_gbkToUTF8.setFont(new Font("宋体", Font.PLAIN, 13));
			text_gbkToUTF8.setBorder(new LineBorder(Color.LIGHT_GRAY));
		}
		return text_gbkToUTF8;
	}

	public JScrollPane getScrollPane_2() {
		if (scrollPane_2 == null) {
			scrollPane_2 = new JScrollPane();
			scrollPane_2.setFont(new Font("Dialog", Font.PLAIN, 12));
			scrollPane_2.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)),
					"UTF8-GBK \u6587\u672C\u66FF\u6362\u89C4\u5219\uFF1A", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			scrollPane_2.setBounds(407, 134, 204, 294);
			scrollPane_2.setViewportView(getText_utf8ToGBK());
		}
		return scrollPane_2;
	}

	public JTextArea getText_utf8ToGBK() {
		if (text_utf8ToGBK == null) {
			text_utf8ToGBK = new JTextArea();
			text_utf8ToGBK.setText("utf8=GBK\r\nutf-8=GBK\r\nUTF8=GBK\r\nUTF-8=GBK");
			text_utf8ToGBK.setFont(new Font("宋体", Font.PLAIN, 13));
			text_utf8ToGBK.setBorder(new LineBorder(Color.LIGHT_GRAY));
		}
		return text_utf8ToGBK;
	}

	public MEComboBox<String> getComboConverType() {
		if (comboConverType == null) {
			comboConverType = new MEComboBox<String>();
			comboConverType.getLabel().setFont(new Font("宋体", Font.PLAIN, 14));
			comboConverType.getComponent().setModel(new DefaultComboBoxModel<String>(new String[] { "GBK To UTF-8", "UTF-8 To GBK" }));
			comboConverType.getLabel().setText("编码转换方向：");
			comboConverType.setBounds(12, 100, 209, 26);
		}
		return comboConverType;
	}

	public MButton getBtn_execute() {
		if (btn_execute == null) {
			btn_execute = new MButton((String) null);
			btn_execute.setText("开始");
			btn_execute.setBounds(775, 100, 101, 32);
			btn_execute.addMouseListener(getEvent());
		}
		return btn_execute;
	}

	public JCheckBox getCheck_iscopynotconverfile() {
		if (check_iscopynotconverfile == null) {
			check_iscopynotconverfile = new JCheckBox("是否拷贝不转换的文件？");
			check_iscopynotconverfile.setSelected(true);
			check_iscopynotconverfile.setBorder(new LineBorder(Color.GRAY));
			check_iscopynotconverfile.setFont(new Font("宋体", Font.PLAIN, 12));
			check_iscopynotconverfile.setBounds(229, 101, 157, 24);
		}
		return check_iscopynotconverfile;
	}
}